package com.huahua.api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huahua.api.base.R;
import com.huahua.api.entity.pojo.ApiNovelBook;
import com.huahua.api.entity.pojo.ApiNovelType;
import com.huahua.api.entity.vo.novel.ApiBookContentVo;
import com.huahua.api.entity.vo.novel.ApiBookVo;
import com.huahua.api.service.ApiNovelBookService;
import com.huahua.api.service.ApiNovelTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author LoveHuahua
 * @date 2021年09月14日 13:54
 * @description believe in yourself
 */
@RestController
@RequestMapping("/novel")
public class NovelController {

    @Autowired
    ApiNovelTypeService typeService;

    @Autowired
    ApiNovelBookService bookService;

    @PostMapping("/getTypeList")
    public R<List<ApiNovelType>> typeList() {
        List<ApiNovelType> list = typeService.list();
        return R.success(list);
    }

    @PostMapping("/getBookListByType")
    public R<List<ApiNovelBook>> getBookListByType(int typeId, int page, int size) {
        Page<ApiNovelBook> apiNovelBookPage = new Page<>(page, size);
        bookService.lambdaQuery().eq(ApiNovelBook::getTypeId, typeId).page(apiNovelBookPage);
        return R.success(apiNovelBookPage.getRecords());
    }

    @PostMapping("/bookDetail")
    public R<ApiBookVo> getBookDetail(int bookId) {
        ApiBookVo bookVo = bookService.getBookDetail(bookId);
        return R.success(bookVo);
    }


    @PostMapping("/bookItemDetail")
    public R<ApiBookContentVo> bookItemDetail(int bookId,int itemId) {
        ApiBookContentVo contentVo = bookService.getBookItemDetail(bookId,itemId);
        return R.success(contentVo);
    }


    @PostMapping("/searchBook")
    public R<Page<ApiNovelBook>> searchBook(String searchKey,Integer page,Integer size) {
        Page<ApiNovelBook> apiNovelBookPage = bookService.searchBook(searchKey,page,size);
        return R.success(apiNovelBookPage);
    }


}
